<script src="script/my_lightbox.js" language="javascript"></script>
<script language="javascript" src="<{$config.weburl}>/script/Calendar.js"></script>
<script language="javascript">
	var cdr = new Calendar("cdr");
	document.write(cdr);
	cdr.showMoreDay = true;
</script>
<{if $add_attach==1}>
<script type="text/javascript" src="<{$config.weburl}>/lib/upload/swfupload/swfupload.js"></script>
<script type="text/javascript" src="<{$config.weburl}>/lib/upload/js/offer_handlers.js"></script>
<script type="text/javascript">
var swfu;	
window.onload = function (){
	swfu = new SWFUpload({
		//Backend Settings
		upload_url: "<{$config.weburl}>/lib/upload/upload.php",
		post_params: {"PHPSESSID": "<?php echo session_id(); ?>",'save_dir':'<{$upload.temp_dir}>','theight':<{$upload.theight}>,'twidth':<{$upload.twidth}>,'file_type':'<{$upload.file_type_param}>'},
		// File Upload Settings
		file_size_limit : "<{$upload.size_limit}>",	//like 2MB
		file_types : "<{$upload.file_type}>",
		file_types_description : "File",
		file_upload_limit : "0",
		file_post_name:'upload_file',
		
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,

		// Button Settings
		button_image_url : "<{$config.weburl}>/lib/upload/images/SmallSpyGlassWithTransperancy_17x18.png",
		button_placeholder_id : "spanButtonPlaceholder",
		button_width: 180,
		button_height: 18,
		button_text : '<span class="button">选择文件<span class="buttonSmall">(2 MB Max)</span></span>',
		button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; } .buttonSmall { font-size: 10pt; }',
		button_text_top_padding: 0,
		button_text_left_padding: 18,
		button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
		button_cursor: SWFUpload.CURSOR.HAND,
		<{if $attach&&$attach|@count==3}>
		button_disabled:true,
		<{/if}>
		// Flash Settings
		flash_url : "<{$config.weburl}>/lib/upload/swfupload/swfupload.swf",

		custom_settings : {
			upload_target : "divFileProgressContainer"
		},
		
		// Debug Settings
		debug:false
	});
initAttachList();
<{if !$de}>
	$('sscatid').value = '';
	$('scatid').value = '';	
	$('tcatid').value = '';
	$('catid').value = '';
<{/if}>
};
function initAttachList()
{
<{if $attach}>
<{foreach item=list from=$attach}>
	initEditImg("<{$list.thumb_img}>",<{$list.id}>,'<{$list.downname}>.<{$list.pic}>');
<{/foreach}>
<{/if}>
	return;
}
</script>
<{elseif !$de}>
<script language="javascript">
	$('sscatid').value = '';
	$('scatid').value = '';	
	$('tcatid').value = '';
	$('catid').value = '';
</script>
<{/if}>
<link href="<{$config.weburl}>/lib/upload/css/default.css" rel="stylesheet">
<style>
#pic_view{width:100%}
#pic_view li{ float:left; width:55px;}
.admin_table{line-height:20px;}
.add_pro
{
	background:url(../../../../image/default/adding.gif) left center no-repeat;
	padding-left:15px;
	font-size:13px;
}
.dele_pro
{
	background:url(../../../../image/default/decrease.gif) left center no-repeat;
	padding-left:15px;
	font-size:13px;
}
ul,li{
	list-style-type:none;
	list-style:none;
}
#thumbnails ul{
	border-top:1px dashed #DDDDDD;
    padding: 10px;
	padding-bottom:20px;
	overflow:hidden;
}
#thumbnails li{
	width:72px;
	height:100px;
	margin-left:15px;
	text-align:center;
	float:left;
}
#thumbnails li .complete_statu{
	border:#DDDDDD solid 1px;
	width:70px;
	display:block;
	height:70px;
}
#thumbnails li h4{
	padding:0;
	margin:0;
	display:inline-block;
	overflow:visible;
	font-size:11px;
	word-wrap: break-word;
	word-break:break-all;
	line-height:14px;
}
#thumbnails li .complete_statu img{
	width:68px;
	height:68px;
	vertical-align:middle;
	margin:0 auto;
}
</style>
<form method="post" action="" enctype="multipart/form-data">
<div class="admin_right_top"><{$lang.trade_post}></div>
<table width="100%" border="0" align="center" cellpadding="6" cellspacing="1" bgcolor="#dddddd" class="admin_table">
       <tr>
          <td width="16%" align="left" bgcolor="#EAEFF3"> <{$lang.type}></td>
          <td width="84%" bgcolor="#FFFFFF" style="font-weight:normal">
		   <{foreach item=list key=num from=$infoType}>
		   <{if $num>0}>
           <input style="border:none; width:20px;" type="radio" <{if $de.type!='0'}>onclick="toggAddPro()"<{/if}> name="type" value="<{$num}>"
		   <{if $de.type==$num||$num==1}>checked="checked"<{/if}> /><{$list}>
			<{/if}>
		   <{/foreach}>
           </td>
        </tr><tr>
              <td bgcolor="#EAEFF3"><{$lang.titles}><font color="red"> *</font> </td>
              <td bgcolor="#FFFFFF">
			  <input maxlength="100" name="title" type="text" id="title" style="width:420px;" value="<{$de.title}>" />               </td>
            </tr>
           <tr>
              <td bgcolor="#EAEFF3"><{$lang.key_words}></td>
              <td bgcolor="#FFFFFF">
			  <input name="keywords" id="key_word" type="text" maxlength="50" value="<{$de.keywords|escape:html}>" style="width:420px;" /><br>
			  <{$lang.key_des}>
              </td>
            </tr>
            <tr>
              <td bgcolor="#EAEFF3"><{$lang.category}><font color="red"> *</font> </td>
              <td bgcolor="#FFFFFF">
              <span id="cate_show"><{$typenames}></span>&nbsp;
              <input type="button" onclick="showCategory();" value="<{$lang.select_business_category}>">
              <input name="catid" id="catid" type="hidden" value="<{$de.catid}>" />
              <input name="tcatid" id="tcatid" type="hidden" value="<{$de.tcatid}>" />
              <input name="scatid" id="scatid" type="hidden" value="<{$de.scatid}>" />
              <input name="sscatid" id="sscatid" type="hidden" value="<{$de.sscatid}>" />
              </td>
            </tr>
                    <tr>
			  <td bgcolor="#EAEFF3"><{$lang.cus_cat}></td>
			  <td bgcolor="#FFFFFF">
              <select name="custom_cat" style="width:133px">
                <option value=""><{$lang.no_cat}></option>
              <{foreach item=list from=$custom_cat}>
              	<{if $de.custom_cat_id==$list.id}>selected="selected"<{/if}> value="<{$list.id}>"><{$list.name}><option <{if $de.custom_cat_id==$list.id}>selected="selected"<{/if}> value="<{$list.id}>"><{$list.name}></option>
              <{/foreach}>
              </select>
              [<a target="_blank" href="main.php?action=m&m=product&s=admin_product_cat&menu=<{$smarty.get.menu}>"><{$lang.mag_cat}></a>]              </td>
    		</tr>
		  <tr>
          <td align="left" bgcolor="#EAEFF3">市场价(<{$config.money}>)</td>
          <td bgcolor="#FFFFFF" style="font-weight:normal">
           <input type="text" name="market_price" id="market_price" style="width:130px;" maxlength="10" value="<{$de.market_price}>" /> /
           <select name="unit" <{if !$de}>onchange="$('pro_unit_des').innerHTML='('+this.value+')'"<{/if}>>
		   <{foreach item=list from=$unit}>
		   <option <{if $list==$de.priceDes}>selected="selected"<{/if}> ><{$list}></option>
		   <{/foreach}>
		   </select>         
           </td>
        </tr>
        <tr>
          <td align="left" bgcolor="#EAEFF3"><{$lang.price}>(<{$config.money}>)</td>
          <td bgcolor="#FFFFFF" style="font-weight:normal">
           <input type="text" name="price" id="price" style="width:130px;" maxlength="10" value="<{$de.price}>" /> /
           <select name="unit" <{if !$de}>onchange="$('pro_unit_des').innerHTML='('+this.value+')'"<{/if}>>
		   <{foreach item=list from=$unit}>
		   <option <{if $list==$de.priceDes}>selected="selected"<{/if}> ><{$list}></option>
		   <{/foreach}>
		   </select>         
           </td>
        </tr>
         <tr>
              <td bgcolor="#EAEFF3"><{$lang.specifications}></td>
              <td bgcolor="#FFFFFF">
			  <input  type="text" id="gg" name="gg" maxlength="30" style="width:170px;" value="<{$de.gg}>" /></td>
            </tr>
			<tr>
              <td bgcolor="#EAEFF3"><{$lang.model}></td>
              <td bgcolor="#FFFFFF">
			  <input  type="text" id="model" name="model" maxlength="30" style="width:170px;" value="<{$de.model}>" /></td>
            </tr>
            <tr>
              <td bgcolor="#EAEFF3"><{$lang.brand}></td>
              <td bgcolor="#FFFFFF">
              	<{if $brand==''}>
					<input type="text" value="<{$de.pp}>" style="width:170px;" name="pinpai" maxlength="30">
				<{else}>
					<{$brand}>
				<{/if}>
              </td>
            </tr>
			<tr>
            <td bgcolor="#EAEFF3"><{$lang.summary}><font color="red"> *</font> </td>
            <td bgcolor="#FFFFFF">
            <textarea maxlength="100" style="width:99%; height:40px;" name="con" id="con"><{$de.con}></textarea>
            </td>
          </tr>           
            <tr>
              <td bgcolor="#EAEFF3"><{$lang.introduction}><font color="red"> *</font> </td>
              <td bgcolor="#FFFFFF">
				<{if $de.detail}>
					<{$de.detail}>
				<{else}>
					<script type="text/javascript" src="lib/fckeditor/fckeditor.js"></script>
					<script type="text/javascript">
					var oFCKeditor = new FCKeditor( 'detail' ) ;
					oFCKeditor.Config['ToolbarStartExpanded'] = true ;
					<{if $config.language=='en'}>
						oFCKeditor.Config['DefaultLanguage']='en';
					<{else}>
						oFCKeditor.Config['DefaultLanguage']='zh-cn';
					<{/if}>
					oFCKeditor.BasePath		= 'lib/fckeditor/' ;
					oFCKeditor.ToolbarSet	= 'frant' ;
					oFCKeditor.Width='100%';
					oFCKeditor.Height=400;
					oFCKeditor.Create() ;
					</script>
				<{/if}>
            </td>
            </tr>
            <tr>
              <td bgcolor="#EAEFF3"><{$lang.validTime}></td>
              <td bgcolor="#FFFFFF" >
              <{foreach item=list key=num from=$validTime}>
			  <input name="validTime" type="radio" value="<{$num}>" <{if $num==$de.valid_time}>checked="checked"<{/if}> />
              <{$list}> 
              <{/foreach}>
              </td>
            </tr>
			<tr>
              <td bgcolor="#EAEFF3"><{$lang.picture}><font color="red"> *</font> </td>
              <td bgcolor="#FFFFFF" valign="middle">
            <div id="pic_view">
              <{if $de.pic}>
               <input name="dele_pic" id="dele_pic" type="hidden" value="" />
              <{foreach item=list from=$de.pic}>
              <li _pic_id="<{$list}>" _pic_statu=1>
              <img src="uploadfile/product/<{$list}>" width="50" height="40"><br>[<a href="javascript:void(0)" onclick="remove_pic('<{$list}>');"><{$lang.delete}></a>]
              </li>
              <{/foreach}>
              <{/if}>
            </div>
			<div style="clear:both;" id="overlay"></div>
            <input type="button"  value="<{$lang.add_pic}>" onclick="alertWin('<{$lang.add_pic}>','',260,130,'upload.php?re_pic=1');" />
            <input name="pic" id="pic" type="hidden" value="" />
            </td>
            </tr>
            <{if $add_attach==1}>
            <tr>
                <td bgcolor="#EAEFF3">上传附件</td>
                <td bgcolor="#FFFFFF">
            <div style="border:solid 1px #7FAAFF;width:180px;height:18px; margin-bottom:3px;background-color: #C5D9FF; padding:2px;margin-top:5px !important; margin-top:0;">
                    <span disabled="disabled" id="spanButtonPlaceholder"></span>
            </div>
            <b id="divFileProgressContainer"></b>
            <div id="thumbnails">
            	<ul>
                	<{section name=li loop=$upload.upload_limit}>
                	<li uploadstatu='0'>
                    	<div class="complete_statu"></div>
                        <h4></h4>
                    </li>
                	<{/section}>
                </ul>
            </div>

                </td>
            </tr>
            <{/if}>
            <tr>
              <td bgcolor="#EAEFF3">&nbsp;</td>
              <td bgcolor="#FFFFFF">
			  <input type="submit" value="<{$lang.submit}>" style="width:50px;" onClick="return check_value();"/>
			  <input name="submit" type="hidden" id="submit" value="<{if $de.id}>edit<{else}>submit<{/if}>" />
			  <input name="editID" type="hidden" id="editID" value="<{$de.id}>" />
              </td>
            </tr>			
</table>
</form>
<script>
function showCategory()
{
	var key= $('key_word').value;
	alertWin('<{$lang.product_category}>','',580,480,'<{$config.weburl}>/cate_show_ajax.php?type=OCAT&key_word='+key);
}
function setCategory(catid)
{
	var url = '<{$config.weburl}>/cate_show_ajax.php?oper=ajax&call=get_cate';
	var sj = new Date();
	var pars = 'shuiji=' + sj+'&type=OCAT&catid='+catid;
	var myAjax = new Ajax.Request(
				url,
				{method: 'post', parameters: pars, onComplete: showResponse}
				);
	function showResponse(originalRequest)
	{
		var tempStr = 'var MyMe = ' + originalRequest.responseText; 
		var i=0;var j=0;
		eval(tempStr);
		if(MyMe)
		{
			$('sscatid').value = '';
			$('scatid').value = '';	
			$('tcatid').value = '';
			$('catid').value = '';
			if(catid.length>8)
				$('sscatid').value = catid;
			if(catid.length>6)
				$('scatid').value = catid.substr(0,8);	
			if(catid.length>4)
				$('tcatid').value = catid.substr(0,6);
			$('catid').value = catid.substr(0,4);
			$('cate_show').innerHTML= MyMe.cat;
			$('brand').innerHTML= MyMe.brand;
			$('fv_box').innerHTML = '<table width="100%">'+MyMe.firstvalue+'</table>';
			if($('fv_list'))
				$('fv_list').style.display=MyMe.firstvalue!=''?'':'none';
		}			

	 }
	close_win();
}
//--------------------------
var city='<{$de.city}>';
var province='<{$de.province}>';
function getHTML(v)
{	
	var ob="city";
	var url = '<{$config.weburl}>/ajax_back_end.php';
	var sj = new Date();
	var pars = 'shuiji=' + sj+'&prov_id='+v;
	var myAjax = new Ajax.Request(
				url,
				{method: 'post', parameters: pars, onComplete: showResponse}
				);
	function showResponse(originalRequest)
	{
		var tempStr = 'var MyMe = ' + originalRequest.responseText; 
		var i=0;var j=0;
		eval(tempStr);
		for(var s in MyMe)
		{
			++j;
		}
		$(ob).options.length =j+1;
		for(var k in MyMe)
		{
			var cityId=MyMe[k][0];
			var ciytName=MyMe[k][1];
			$(ob).options[k].value = cityId;
			$(ob).options[k].text = ciytName;
			if(city!=''&&city==ciytName)
				$(ob).options[k].selected = true;
	　	}
	 }
　}
<{if $de.city}>
getHTML('<{$de.province}>');
<{/if}>
//==========================================
function check_value()
{
	if(!$('title').value)
	{
		alert('<{$lang.notice_title}>');
		$('title').focus();
		return false;
	}
	if($('catid').value=='')
	{
		alert('<{$lang.product_category}>');
		return false;
	}
	if($('con').value.length>199) 
	{
		alert("<{$lang.sumisbig}>");
		return false;
	}
	if(!$('con').value) 
	{
		alert("<{$lang.notice_con}>");
		return false;
	} 
    var fck = FCKeditorAPI.GetInstance("detail");
    var content = fck.GetXHTML(true);
    if (content.replace(/<(?!img|input|object)[^>]*>|\s+/ig, "") == "")
	{
	   alert("<{$lang.notice_detail}>");
	   fck.Focus();
	   return false;
    }
}
//=========================================
var arr = new Array()
function load_pic(v)
{
	if(v!=''&&!arr.inArray(v))
	{	
		arr.push(v);
		var pic = document.createElement('li');
		pic.setAttribute('_pic_statu',0);
		pic.setAttribute('_pic_id',v);
		pic.innerHTML = '<img src="uploadfile/product/thumb/'+v+'.jpg" width="50" height="40"><br>['+
		'<a href="javascript:void(0)" onclick="cannel_pic(\''+v+'\')"><{$lang.delete}></a>]';
		$('pic_view').appendChild( pic );
	}
	$('pic').value=arr.join();
	close_win();
}
Array.prototype.inArray = function(valeur) 
{
	for(var i in this) 
	{ 
		if (this[i] === valeur) 
			return true; 
	}
	return false;
}
Array.prototype.remove=function(dx)
{
	for(var i=0,n=0;i<this.length;i++)
	{
		if(this[i]!=dx)
		{
			this[n++]=this[i]
		}
	}
	this.length-=1
}
function cannel_pic(v)
{
	arr.remove(v);
	var pBoxLi = $('pic_view').getElementsByTagName('li');
	for(var i=0;i<pBoxLi.length;i++){
		if(pBoxLi[i].getAttribute('_pic_statu')==0&&pBoxLi[i].getAttribute('_pic_id')==v){
			$('pic_view').removeChild(pBoxLi[i]);
			$('pic').value = arr.join();
			return;
		}
	}	
}
function remove_pic(id){
	$('dele_pic').value=$('dele_pic').value+','+id;
	var pBoxLi = $('pic_view').getElementsByTagName('li');
	for(var i=0;i<pBoxLi.length;i++){
		if(pBoxLi[i].getAttribute('_pic_statu')==1&&pBoxLi[i].getAttribute('_pic_id')==id){
			$('pic_view').removeChild(pBoxLi[i]);
			return;
		}
	}	
	
}
</script>